package letsjava.pattern.strategy;

public class RepTempRuleSolve {
	private RepTempRule strategy;

	public RepTempRuleSolve(RepTempRule rule) {
		this.strategy = rule;
	}

	public String getNewContext(String oldString) throws Exception {
		return strategy.replace(oldString);
	}

	public void changeAlgorithm(RepTempRule newAlgorithm) {
		strategy = newAlgorithm;
	}
	
	public static void main(String[] args) throws Exception{
		//使用第一套替代方案 
		RepTempRuleSolve solver=new RepTempRuleSolve(new RepTempRuleOne()); 
		System.out.println(solver.getNewContext("dddaaaabbb"));
		
		//使用第二套
		solver.changeAlgorithm(new RepTempRuleTwo()); 
		System.out.println(solver.getNewContext("dddaaaabbb"));
		
	}
}